import requests

from contant.gaode import *


class GaodeTerminalService:
    @classmethod
    def add_terminal(cls, sid: str, name: str, desc: str):
        """
        新增终端
        :param sid: 服务编号
        :param name: 终端名称
        :param desc: 终端描述
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid,
            'name': name,
            'desc': desc
        }
        # 发送HTTP请求
        response = requests.post(GAODE_TERMINAL_ADD, data=post_data)
        # 解析JSON响应
        data = response.json()
        return data

    @classmethod
    def update_terminal(cls, sid: str, tid: str, name: str, desc: str):
        """
        修改终端
        :param sid: 服务编号
        :param tid: 终端编号
        :param name: 终端名称
        :param desc: 终端描述
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid,
            'tid': tid,
            'name': name,
            'desc': desc
        }
        # 发送HTTP请求
        response = requests.post(GAODE_TERMINAL_ADD, data=post_data)
        # 解析JSON响应
        data = response.json()
        return data

    @classmethod
    def delete_terminal(cls, sid: str, gfid: str, tids: str):
        """
        删除终端
        :param sid: 服务编号
        :param tid: 终端编号
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': sid,
            'gfid': gfid,
            'tids': tids
        }
        # 发送HTTP请求
        response = requests.post(GAODE_TERMINAL_DELETE, data=post_data)
        # 解析JSON响应
        data = response.json()
        return data

    @classmethod
    def query_terminal(cls, service_id: str, terminal_id: str):
        """
        查询终端列表
        :return: 接口调用结果
        """
        post_data = {
            'key': GAODE_KEY,
            'sid': service_id,
            'name': terminal_id
        }
        # 发送HTTP请求
        response = requests.get(GAODE_TERMINAL_LIST, params=post_data)
        # 解析JSON响应
        data = response.json()
        return data
